(function() {
  app.controller('vipDealQueryCtrl', function(returnData, $scope, local_m, vipIndex, $state, bottomdilog, tradeApi, centerdilog) {
    $scope.condition = [{
        head: '交易方向',
        options: [
          { txt: '全部', value: 'all' },
          { txt: '买入', value: '0' },
          { txt: '卖出', value: '1' },
        ],
        default: { txt: '全部', value: 'all' },
      },
      {
        head: '成交日期',
        options: [
          { txt: '全部', value: 90 },
          { txt: '当天', value: 1 },
          { txt: '7天之内', value: 7 },
          { txt: '15天之内', value: 15 },
        ],
        default: { txt: '当天', value: 1 },
      }
    ];

    $scope.dir_cards = {
      data: [],
      config: {
        title: {
          css: {},
          content: { 'key1': 'stkcode', 'key2': 'stkname', 'split': '--' },
        },
        rows: {
          css: {
            left: {},
            right: {
              color: '#333333'
            }
          },
          content: [
            { txt: '成交价格', key: 'matchprice', unit: '元 / 股' },
            { txt: '成交数量', key: 'matchamt', unit: '股' },
            { txt: '成交金额', key: 'matchbalance', unit: '元' },
            { txt: '交易方向', key: 'bstype' },
            { txt: '成交时间', key: 'martchdate', key2: 'matchtime' },
          ],
        },
        buttons: {
          ok_show: false,
          cancel_show: false,
        },
        state: {
          show: false,
        }
      },
    };

    $scope.init = function() {
      var data = returnData.dateSet($scope.condition[1].default.value, 'yyyyMMdd');
      data.funcid = '3';
      $scope.client_deal_query(data);
    };

    $scope.client_deal_query = function(data) {
      tradeApi
        .etQuery(data)
        .then(function(res) {
          if ($scope.condition[0].default.txt !== '全部') {
            for (var i = 0; i < res.length; i++) {
              if (res[i].bstype !== $scope.condition[0].default.txt) {
                res.splice(i, 1);
                i--;
              }
            }
          }
          $scope.dir_cards.data = res;
        });
    };
  });

})();